<template>
  <div>
    <h1>Reply</h1>
    <!--搜索框-->
    <el-form :inline="true" ref="form" :model="queryLike" label-width="80px">
      <el-form-item label="评论楼id">
        <el-input v-model="queryLike.coid" placeholder="输入要查找的评论楼id"></el-input>
      </el-form-item>
      <el-form-item label="评论者id">
        <el-input v-model="queryLike.from" placeholder="输入要查找的评论者id"></el-input>
      </el-form-item>
      <el-form-item label="回复对象id">
        <el-input v-model="queryLike.to" placeholder="输入要查找的回复对象id"></el-input>
      </el-form-item>
      <br>
      <el-form-item label="评论内容">
        <el-input v-model="queryLike.context" placeholder="输入要查找的评论内容"></el-input>
      </el-form-item>
      <el-form-item label="点赞数">
        <el-input v-model="queryLike.like" placeholder="输入要查找的点赞数"></el-input>
      </el-form-item>
      <el-form-item label="状态码">
        <el-radio-group v-model="queryLike.state">
          <el-radio :label="1">正常</el-radio>
          <el-radio :label="0">封禁</el-radio>
          <el-radio :label="''">所有</el-radio>
        </el-radio-group>
      </el-form-item>
      <br>
      <el-form-item label="创建时间">
        <el-col :span="11">
          <el-date-picker type="date" placeholder="选择开始日期" v-model="queryLike.startTime1"
                          style="width: 100%;"></el-date-picker>
        </el-col>
        <el-col class="line" :span="2" style="text-align:center">-</el-col>
        <el-col :span="11">
          <el-time-picker placeholder="选择开始时间" v-model="queryLike.startTime2" style="width: 100%;"></el-time-picker>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-col :span="11">
          <el-date-picker type="date" placeholder="选择结束日期" v-model="queryLike.endTime1"
                          style="width: 100%;"></el-date-picker>
        </el-col>
        <el-col class="line" :span="2" style="text-align:center">-</el-col>
        <el-col :span="11">
          <el-time-picker placeholder="选择结束时间" v-model="queryLike.endTime2" style="width: 100%;"></el-time-picker>
        </el-col>
      </el-form-item>
      <br>
      <el-form-item label="排序类型">
        <el-radio-group v-model="queryLike.sortType">
          <el-radio :label="1">降序</el-radio>
          <el-radio :label="0">升序</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="排序依据">
        <el-radio-group v-model="queryLike.sortBy">
          <el-radio :label="10">创建时间</el-radio>
          <el-radio :label="2">价格</el-radio>
          <el-radio :label="0">浏览量</el-radio>
          <el-radio :label="1">月销量</el-radio>
          <el-radio :label="3">修改时间</el-radio>
        </el-radio-group>
      </el-form-item>
      <br>
      <el-form-item label="页数">
        <el-input v-model="queryLike.page" width="20" placeholder="输入当前页"></el-input>
      </el-form-item>
      <el-form-item label="页内条数">
        <el-input v-model="queryLike.pageSize" width="20" placeholder="输入单页总条数"></el-input>
      </el-form-item>
      <el-form-item>
        <!--查询按钮-->
        <el-button type="primary" @click="search(queryLike)" icon="el-icon-search" value="查询"></el-button>
        <el-form-item label="回复者类型" :label-width="formLabelWidth">
          <el-switch
            v-model="mode_user"
            active-color="#ff4949"
            inactive-color="#13ce66"
            active-text="商家"
            inactive-text="顾客"
          >
          </el-switch>
        </el-form-item>
        <el-form-item label="回复对象类型" :label-width="formLabelWidth">
          <el-switch
            v-model="mode_user_reply"
            active-color="#ff4949"
            inactive-color="#13ce66"
            active-text="商家"
            inactive-text="顾客"
          >
          </el-switch>
        </el-form-item>
        <!--添加按钮-->
        <el-button style="float:right" type="success" icon="el-icon-circle-plus-outline" @click="insert()"
                   value="添加"></el-button>
      </el-form-item>
    </el-form>
    <!--添加填出的对话框(和修改是同一个)-->
    <el-dialog title="回复评论" :visible.sync="dialogFormVisible">
      <el-form :model="pojo">
        <el-form-item label="回复者类型" :label-width="formLabelWidth">
          <el-switch
            v-model="mode_user"
            active-color="#ff4949"
            inactive-color="#13ce66"
            active-text="商家"
            inactive-text="顾客"
          >
          </el-switch>
        </el-form-item>
        <el-form-item label="评论楼id" :label-width="formLabelWidth">
          <el-input v-model="pojo.coid" autocomplete="on"></el-input>
        </el-form-item>
        <el-form-item label="评论者id" :label-width="formLabelWidth">
          <el-input v-if="pojo.from!==null&&pojo.from!==undefined&&pojo.from.cid!==undefined&&pojo.from.cid!==null"
                    v-model="pojo.from.cid" autocomplete="on"></el-input>
          <el-input v-if="pojo.from!==null&&pojo.from!==undefined&&pojo.from.mid!==undefined&&pojo.from.mid!==null"
                    v-model="pojo.from.mid" autocomplete="on"></el-input>
        </el-form-item>
        <el-form-item label="回复对象类型" :label-width="formLabelWidth">
          <el-switch
            v-model="mode_user_reply"
            active-color="#ff4949"
            inactive-color="#13ce66"
            active-text="商家"
            inactive-text="顾客"
          >
          </el-switch>
        </el-form-item>
        <el-form-item label="回复对象id" :label-width="formLabelWidth">
          <el-input
            v-if="pojo.to!==null&&pojo.to!==undefined&&pojo.to.cid!==undefined&&pojo.to.cid!==null"
            v-model="pojo.to.cid" autocomplete="on"></el-input>
          <el-input
            v-if="pojo.to!==null&&pojo.to!==undefined&&pojo.to.mid!==undefined&&pojo.to.mid!==null"
            v-model="pojo.to.mid" autocomplete="on"></el-input>
        </el-form-item>
        <div title="评论内容">
          <el-card style="height: 610px;">
            <!--富文本-->
            <quill-editor v-model="pojo.context" ref="myQuillEditor" style="height: 500px;" :options="editorOption"
                          @blur="onEditorBlur($event)" @focus="onEditorFocus($event)"
                          @change="onEditorChange($event)"
            >
              <!-- 自定义toolar -->
              <div id="toolbar" slot="toolbar">
                <!-- Add a bold button -->
                <button class="ql-bold" title="加粗">Bold</button>
                <button class="ql-italic" title="斜体">Italic</button>
                <button class="ql-underline" title="下划线">underline</button>
                <button class="ql-strike" title="删除线">strike</button>
                <button class="ql-blockquote" title="引用"></button>
                <button class="ql-code-block" title="代码"></button>
                <button class="ql-header" value="1" title="标题1"></button>
                <button class="ql-header" value="2" title="标题2"></button>
                <!--Add list -->
                <button class="ql-list" value="ordered" title="有序列表"></button>
                <button class="ql-list" value="bullet" title="无序列表"></button>
                <!-- Add font size dropdown -->
                <select class="ql-header" title="段落格式">
                  <option selected>段落</option>
                  <option value="1">标题1</option>
                  <option value="2">标题2</option>
                  <option value="3">标题3</option>
                  <option value="4">标题4</option>
                  <option value="5">标题5</option>
                  <option value="6">标题6</option>
                </select>
                <select class="ql-size" title="字体大小">
                  <option value="10px">10px</option>
                  <option value="12px">12px</option>
                  <option value="14px">14px</option>
                  <option value="16px" selected>16px</option>
                  <option value="18px">18px</option>
                  <option value="20px">20px</option>
                  <option value="20px">22px</option>
                  <option value="20px">24px</option>
                  <option value="20px">26px</option>
                  <option value="20px">28px</option>
                  <option value="20px">30px</option>
                </select>
                <select class="ql-font" title="字体">
                  <option value="SimSun">宋体</option>
                  <option value="SimHei">黑体</option>
                  <option value="Microsoft-YaHei">微软雅黑</option>
                  <option value="KaiTi">楷体</option>
                  <option value="FangSong">仿宋</option>
                  <option value="Arial">Arial</option>
                </select>
                <!-- Add subscript and superscript buttons -->
                <select class="ql-color" value="color" title="字体颜色"></select>
                <select class="ql-background" value="background" title="背景颜色"></select>
                <select class="ql-align" value="align" title="对齐"></select>
                <button class="ql-clean" title="还原"></button>
                <!-- You can also add your own -->
                <button class="ql-link" title="链接"></button>
                <button class="ql-image" title="图片"></button>
                <button class="ql-video" title="视频"></button>
              </div>
            </quill-editor>
          </el-card>
        </div>
        <el-form-item label="点赞量" :label-width="formLabelWidth">
          <el-input v-model="pojo.like" autocomplete="on"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="save(pojo)">确 定</el-button>
      </div>
    </el-dialog>
    <!--内容对话框-->
    <el-dialog
      title="全文"
      :visible.sync="centerDialogVisible"
      width="30%"
      center>
      <p v-html="this.content"></p>
    </el-dialog>
    <!--列表-->
    <el-table :data="user" style="width: 100%" max-height="600">
      <el-table-column fixed property="reid" label="主键"></el-table-column>
      <el-table-column property="coid" label="评论楼id"></el-table-column>
      <el-table-column property="from" label="评论者">
        <template slot-scope="scope">
          <a v-if="scope.row.from.cid!==null&&scope.row.from.cid!==undefined">
            <{{ scope.row.from.cid }}>{{ scope.row.from.name }}
          </a>
          <a v-if="scope.row.from.mid!==null&&scope.row.from.mid!==undefined">
            <{{ scope.row.from.mid }}>{{ scope.row.from.name }}
          </a>
        </template>
      </el-table-column>
      <el-table-column property="from" label="评论者头像">
        <template slot-scope="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="baseURL+'data/picture/'+scope.row.from.pic.url"
            :preview-src-list="[baseURL+'data/picture/'+scope.row.from.pic.url]"
            fit='cover'
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column property="to" label="回复对象">
        <template slot-scope="scope">
          <a v-if="scope.row.to!=null&&scope.row.to!==undefined&&scope.row.to.cid!==null&&scope.row.to.cid!==undefined">
            <{{ scope.row.to.cid }}>{{ scope.row.to.name }}
          </a>
          <a v-if="scope.row.to!=null&&scope.row.to!==undefined&&scope.row.to.mid!==null&&scope.row.to.mid!==undefined">
            <{{ scope.row.to.mid }}>{{ scope.row.to.name }}
          </a>
        </template>
      </el-table-column>
      <el-table-column property="to" label="回复对象头像">
        <template slot-scope="scope">
          <el-image
            v-if="scope.row.to!==null&&scope.row.to!==undefined"
            style="width: 100px; height: 100px"
            :src="baseURL+'data/picture/'+scope.row.to.pic.url"
            :preview-src-list="[baseURL+'data/picture/'+scope.row.to.pic.url]"
            fit='cover'
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column property="context" label="评论内容">
        <template slot-scope="scope">
          <p v-html="scope.row.context" class="product-buyer-name"></p>
          <el-button type="text" @click="Content(scope.row.context)">查看完整内容</el-button>
        </template>
      </el-table-column>
      <el-table-column property="like" label="点赞量" width="150"></el-table-column>
      <el-table-column property="state" label="状态码" width="150"></el-table-column>
      <el-table-column property="creattime" label="创建时间" width="150"></el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="200">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-setting" value="修改" @click="change(scope.row)" circle></el-button>
          <el-button v-if="scope.row.state===1" type="info" icon="el-icon-video-pause" value="封禁"
                     @click="dele(scope.row)" circle></el-button>
          <el-button v-if="scope.row.state!==1" type="info" icon="el-icon-video-play" value="启用"
                     @click="enable(scope.row)" circle></el-button>
          <el-button v-if="power===3" type="danger" icon="el-icon-delete" value="删除" @click="phydele(scope.row)"
                     circle></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {
  Quill,
  quillEditor
} from 'vue-quill-editor'
import '../../../src/assets/css/font.css'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

let Size = Quill.import('attributors/style/size')
Size.whitelist = ['10px', '12px', '14px', '16px', '18px', '20px', '22px', '24px', '26px', '28px', '30px']
Quill.register(Size, true)

// 自定义字体类型
let fonts = ['SimSun', 'SimHei', 'Microsoft-YaHei', 'KaiTi', 'FangSong', 'Arial', 'Times-New-Roman', 'sans-serif',
  '宋体', '黑体'
]
let Font = Quill.import('formats/font')
Font.whitelist = fonts
Quill.register(Font, true)
export default {
  name: "Reply",
  props: {},
  components: {quillEditor},
  data() {
    return {
      /**
       * @评论回复用户类型
       * */
      mode_user: '顾客',
      /**
       * @评论回复对象类型
       * */
      mode_user_reply: '顾客',
      /**
       * @富文本默认内容
       * */
      editorOption: {
        placeholder: "请输入",
        theme: "snow", // or 'bubble'
        modules: {
          toolbar: {
            container: '#toolbar'
          }
        }
      },
      /**
       * @介绍内文
       * */
      content: "",
      /**
       * @展示内容
       * */
      centerDialogVisible: false,
      /***
       * @修改和添加数据类型
       * */
      pojo: this.$store.state.Pojo.ReplyVo,
      /**
       * @弹出的对话框,用于修改和添加数据
       * */
      dialogFormVisible: false,
      /**
       * @对话框内条目的统一长度
       * */
      formLabelWidth: '120px',
      /**
       * @表单数据
       * */
      user: this.$store.state.List.ReplyVo,
      /**
       * @权限,页面显示不同权限的操作
       * */
      power: this.$store.state.operator.power,
      /**
       * @查询条件
       * */
      queryLike: {
        OperatorId: "",
        endTime1: "2099-01-01 00:00:00.000+0000",
        endTime2: "2099-01-01 00:00:00.000+0000",
        coid: "",
        from: "",
        to: "",
        context: "",
        like: "",
        state: "",
        page: 1,
        pageSize: 10,
        sortBy: 10,
        sortType: 1,
        startTime1: "2000-01-01 00:00:00.000+0000",
        startTime2: "2000-01-01 00:00:00.000+0000",
      },
      /**
       * @后端controller名字
       * */
      controller: 'Reply',
    };
  },
  computed: {
    baseURL() {
      return this.$store.state.baseURL;
    }
  },
  /**
   * @加载数据
   */
  created() {
    this.LoadMsg();
  },
  /**
   * @static方法
   * */
  mounted() {
    (() => {
      /*console.log(this.$store.state.operator)
      this.power=this.$store.state.operator["power"];
      console.log(this.power);
      console.log(typeof (this.power))*/
    })();
  },
  methods: {
    /**
     * @失去焦点事件
     * */
    onEditorBlur() {
    },
    /**
     * @获得焦点事件
     * */
    onEditorFocus() {
    },
    /**
     * @内容改变事件
     * */
    onEditorChange() {
    },
    /**
     * @嵌入内容
     * */
    Content(val) {
      this.centerDialogVisible = true;
      this.content = val;
    },
    /**
     * @添加
     * */
    insert() {
      this.pojo.reid = "";
      this.pojo.coid = "";
      if (this.mode_user === false) {
        this.pojo.from={cid : ""};
      } else {
        this.pojo.from={mid : ""};
      }
      if (this.mode_user_reply === false) {
        this.pojo.to={cid : ""};
      } else {
        this.pojo.to={mid : ""};
      }
      this.pojo.context = "这个人很懒,什么也没有写";
      this.pojo.like = 0;
      this.pojo.state = 1;
      //console.log(this.pojo.from)
      this.dialogFormVisible = true;
    },
    /**
     * @修改
     * */
    change(val) {
      //console.log(val)
      this.pojo = this.$helper.clone(val);
      if (this.mode_user_reply === false&&(this.pojo.to===null||this.pojo.to===undefined)) {
        this.pojo.to={cid : ""};
      } else if(this.pojo.to===null||this.pojo.to===undefined){
        this.pojo.to={mid : ""};
      }
      this.dialogFormVisible = true;
    },
    /**
     * @保存
     */
    save(val) {
      console.log(val)
      let _this = this;
      this.axios.post(this.$store.state.baseURL + 'client/' + this.controller + '/save?' + 'OperatorId=' + this.$store.state.operator.id,
        {
          reid: val.reid,
          coid: val.coid,
          from: val.from,
          to: val.to,
          context: val.context,
          like: val.like,
          state: val.state
        })
        .then(res => {
          console.log(res.data)
          _this.search(_this.queryLike);
        })
      this.dialogFormVisible = false;
    },
    /**
     * @启用
     */
    enable(val) {
      let _this = this;
      this.axios.post(this.$store.state.baseURL + 'client/' + this.controller + '/save?' + 'OperatorId=' + this.$store.state.operator.id, {
        reid: val.reid,
        state: 1
      })
        .then(res => {
          _this.search(_this.queryLike);
        })
    },
    /**
     * @物理删除
     */
    phydele(val) {
      let _this = this;
      this.axios.delete(this.$store.state.baseURL + 'client/' + this.controller + '/delete?' + 'OperatorId=' + this.$store.state.operator.id + '&id=' + val.reid)
        .then(res => {
          _this.search(_this.queryLike);
        })
    },
    /**
     * @封禁
     */
    dele(val) {
      let _this = this;
      this.axios.post(this.$store.state.baseURL + 'client/' + this.controller + '/save?' + 'OperatorId=' + this.$store.state.operator.id,
        {
          reid: val.reid,
          state: 0
        })
        .then(res => {
          _this.search(_this.queryLike);
        })
    },
    /**
     * @查询
     * */
    search(val) {
      let _this = this;
      //console.log(val);
      this.axios.get(this.$store.state.baseURL + 'client/' + this.controller + '/queryLike?'
        + 'OperatorId=' + this.$store.state.operator.id
        + '&coid=' + val.coid
        + '&from=' + val.from
        + '&to=' + val.to
        + '&context=' + val.context
        + '&like=' + val.like
        + '&sortBy=' + val.sortBy
        + '&sortType=' + val.sortType
        + '&page=' + val.page
        + '&state=' + val.state
        + '&pageSize=' + val.pageSize
        + '&startTime=' + this.$helper.renderTime(val.startTime1).split(' ')[0] + ' ' + this.$helper.renderTime(val.startTime2).split(' ')[1]
        + '&endTime=' + this.$helper.renderTime(val.endTime1).split(' ')[0] + ' ' + this.$helper.renderTime(val.endTime2).split(' ')[1]
      )
        .then(res => {
          _this.$store.state.List.ReplyVo = res.data;
          _this.LoadInfo(res.data);
          //console.log(_this.user);
        })
    }
    ,
    /**
     *
     * @导入具体列表的数据
     */
    LoadMsg() {
      let _this = this;
      this.axios.get(this.$store.state.baseURL + 'client/' + this.controller + '/queryLike?' + 'OperatorId=' + this.$store.state.operator.id)
        .then(res => {
          _this.$store.state.List.ReplyVo = res.data;
          _this.LoadInfo(res.data);
          console.log(res.data);
        })
    }
    ,
    /**
     *
     * @更新当前页面的数据(data<->this.$store.state)
     */
    LoadInfo(val) {
      this.user = val;
    }
    ,
  },
}
</script>

<style scoped>
.line-limit-length {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap; /*文本不换行，这样超出一行的部分被截取，显示...*/
}

.product-buyer-name {
  max-width: 180px;
  max-height: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.el-select .el-input {
  width: 130px;
}

.input-with-select .el-input-group__prepend {
  background-color: #fff;
}

.el-tag + .el-tag {
  margin-left: 10px;
}

.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}

.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
</style>
